﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Data.Model;

namespace ZLCMS.Web.SystemManage.weixin.Interaction
{
    public partial class VoteItemList : System.Web.UI.Page
    {
        protected ZLCMS.Business.DwzFrame.FrameHelper _framePage;

        protected void Page_Load(object sender, EventArgs e)
        {
            _framePage = new ZLCMS.Business.DwzFrame.FrameHelper(this);
            
            //设置分页大小
            int pageSize = _framePage.IsAjaxPagerPostBack ? _framePage.PageSize : 20;

            //设置页码
            int pageIndex = _framePage.IsAjaxPagerPostBack ? _framePage.PageIndex : 1;

            using (NHibernate.ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                //设置记录总数
                _framePage.RecordCount = Convert.ToInt32(session.CreateQuery("select count(*) from WxVoteItem where ConfigId=:vid")
                    .SetParameter("vid", Int32.Parse(Request["vid"]))
                    .UniqueResult());
                
                //设置数据源
                repeater1.DataSource = session.CreateQuery("from WxVoteItem where ConfigId=:vid order by Sort")
                    .SetParameter("vid", Int32.Parse(Request["vid"]))
                    .SetFirstResult((pageIndex - 1) * pageSize)
                    .SetMaxResults(pageSize)
                    .List<WxVoteItem>();
            }

            repeater1.DataBind();
        }
    }
}